/**
 * 时间戳格式化
 * @param 1403058804
 * @return 2014-06-18 10:33:24
 */
function timestampToTime(timestamp) {
  let date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
  let Y = date.getFullYear() + '-';
  let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
  let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
  let s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
  return Y + M + D + h + m + s;
}

/**
 * 时间转时间戳
 * @param '2014-04-23 18:55:49'
 * @return 1398250549123
 */
function timeToTimestamp(time) {
  let date = new Date(time.replace(/\-/g, "/"));
  return date.getTime();
}

/**
 * 时间戳格式化
 * @param 1403058804
 * @return 18日 10:33
 */
function timesToTime2(timestamp) {
  let date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
  let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + '日 ';
  let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours())  + ':';
  let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
  return D + h + m;
}

/**
 * 获取当前时间戳
 */
function getNowTime() {
  return new Date().getTime();
}

module.exports = {
  timestampToTime: timestampToTime,
  timeToTimestamp: timeToTimestamp,
  timesToTime2: timesToTime2,
  getNowTime: getNowTime
}